<template>
  <div class="home" :style="{ background: 'url(' + personImg + ') no-repeat' }">
    <div class="back" @click="goPage('home')">返回</div>
    <div class="imgBox">
      <img class="r1" src="@/assets/img/ranking2.png" /><br />
      <img class="r2" src="@/assets/img/ranking1.png" />
    </div>
    <div class="ranking" :style="{ background: 'url(' + r3 + ') no-repeat' }">
      <div class="rankingBox">
        <span class="me">我的排名：{{ rankingNum }}</span>
        <ul>
          <li class="item" v-for="(item, index) in ranking" :key="index">
            <div>
              <span class="line">
                <span v-if="index === 0"
                  ><img src="@/assets/img/ranking5.png" alt=""
                /></span>
                <span v-else-if="index === 1"
                  ><img src="@/assets/img/ranking6.png" alt=""
                /></span>
                <span v-else-if="index === 2"
                  ><img src="@/assets/img/ranking4.png" alt=""
                /></span>
                <span v-else>{{ index + 1 }}</span>
              </span>
              <img class="avatar" :src="changeHead(item.head_thumb)" alt="" />
              <span :class="index < 3 ? 'top' : ''">{{ item.name }}</span>
            </div>
            <div>
              <span :class="index < 3 ? 'top' : ''">{{ item.mobile }}</span>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import wx from "weixin-jsapi";
import personImg from "@/assets/img/rankingBg.jpg";
import r3 from "@/assets/img/ranking3.png";
import { Popup, Landscape, Button, Toast, PopupTitleBar } from "mand-mobile";
export default {
  name: "index",
  components: {
    [Popup.name]: Popup,
    [Landscape.name]: Landscape,
    [Button.name]: Button,
    [PopupTitleBar.name]: PopupTitleBar
  },
  data() {
    return {
      personImg: personImg,
      r3: r3,
      rankingNum: "",
      ranking: []
    };
  },
  methods: {
    changeHead(url) {
      if (url) {
        let prefix = "https://www.hrycf.com/";
        if (url.indexOf("/uploads/headimg") !== -1) {
          return prefix + url;
        } else {
          return prefix + "uploads/headimg/" + url;
        }
      } else {
        return "https://test.hrycf.com/front/avatar.jpg";
      }
    },
    goPage(routeName) {
      this.$router.push({ name: routeName });
    },
    getNoticeList() {
      this.$ajax
        .post(this.$api.getNoticeList, false, true)
        .then(res => {
          this.ranking = res.data.list;
          this.rankingNum = res.data.num;
        })
        .catch(err => {
          Toast.failed(err, 3000, true);
        });
    },
    getConfig() {
      wx.ready(() => {
        this.wxShare();
      });
    },
    wxShare() {
      let self = this;
      const share_title = "答题押电影，豪礼领不停！";
      const share_desc =
        "是时候展现你的票房预测能力了，签到再答题，福鼠天天送，瓜分新年豪礼！";
      const share_link = "http://gift.hrycf.com";
      const share_img = "https://test.hrycf.com/hry/gift/cj.png";
      wx.showOptionMenu();
      wx.onMenuShareTimeline({
        title: share_title, // 分享标题
        link: share_link, // 分享链接
        imgUrl: share_img
      });
      wx.onMenuShareAppMessage({
        title: share_title, // 分享标题
        desc: share_desc, // 分享描述
        link: share_link, // 分享链接
        imgUrl: share_img,
        success: function() {
          self.getOneOpportunity();
        }
      });
    }
  },
  mounted() {
    this.getConfig();
  },
  created() {
    this.getNoticeList();
  }
};
</script>

<style scoped lang="less">
.home {
  height: 100%;
  width: 100%;
  position: relative;
  padding: 81px 0 0 0;
  background-size: 100%, 100% !important;
  @media (max-width: 320px) {
    padding: 30px 0 0 0;
  }
  .back {
    position: fixed;
    padding: 20px 50px;
    top: 20px;
    left: 30px;
    font-weight: bold;
    color: white;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 40px;
  }
  .imgBox {
    text-align: center;
    .r1 {
      width: 463px;
      @media (max-width: 360px) {
        width: 400px;
      }
    }
    .r2 {
      width: 588px;
      margin-top: -40px;
      @media (max-width: 320px) {
        width: 400px;
      }
      @media (max-width: 360px) {
        width: 440px;
      }
    }
  }
  .ranking {
    padding: 84px 65px;
    width: 724px;
    height: 834px;
    margin: 0 auto;
    background-size: 100%, 100% !important;
    .rankingBox {
      width: 100%;
      height: 100%;
      overflow-y: auto;
      font-size: 26px;
      font-family: PingFang SC;
      font-weight: 500;
      color: rgba(102, 102, 102, 1);
    }
    .me {
      font-size: 30px;
      font-family: PingFang SC;
      font-weight: 500;
      color: rgba(190, 12, 24, 1);
      margin-bottom: 34px;
      display: inline-block;
    }
    .top {
      color: rgba(190, 12, 24, 1);
    }
    .item {
      padding: 27px;
      border-bottom: 1px solid rgba(255, 248, 232, 0.7);
      .flex_content ();
      .flex_justify_space();
      .flex_align_center ();
    }
    .line {
      display: inline-block;
      font-size: 30px;
      font-family: PingFang SC;
      font-weight: bold;
      color: rgba(102, 102, 102, 1);
      margin-right: 42px;
      text-align: center;
      width: 45px;
      img {
        width: 45px;
        vertical-align: middle;
      }
    }
    .avatar {
      width: 65px;
      height: 65px;
      border-radius: 50%;
      vertical-align: middle;
      margin-right: 27px;
    }
  }
}
</style>
